<template>
  <div class="app-container">

      <el-row :gutter="20" :show-overflow-tooltip="true">
        <!--部门数据-->
        <el-col :span="4" :xs="24">
          <div class="head-container">
            <el-input
              v-model="domainName"
              placeholder="请输入领域名称"
              clearable
              size="small"
              prefix-icon="el-icon-search"
              style="margin-bottom: 20px"
            />
          </div>
          <div class="head-container" style="min-width:200px">
            <el-tree
              :data="domainOptions"
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              :default-expand-all="true"
              :auto-expand-parent="true"
              ref="tree"
              @node-click="handleNodeClick"
            />
          </div>
        </el-col>
        <!--用户数据-->
        <el-col :span="20" :xs="24" >
          <div v-for="question in surveyList"  ><question-item :element="question"> </question-item></div>

          <el-form>
          <el-form-item label="得分比例(0~100%)" prop="scoreWeight">
            <el-input-number v-model="form.scoreWeight" placeholder="请输入得分比例" :max="100" :min="0"/>
          </el-form-item>
          <el-form-item label="现状描述">
            <editor v-model="form.questionDesc" :min-height="192"/>
          </el-form-item>
          <el-form-item label="诊断意见">
            <editor v-model="form.suggestion" :min-height="192"/>
          </el-form-item>
          <el-form-item label="后续工作">
            <editor v-model="form.todo" :min-height="192"/>
          </el-form-item>
          <el-form-item label="工作计划">
            <editor v-model="form.plan" :min-height="192"/>
          </el-form-item>
          </el-form>
        </el-col>
      </el-row>
  </div>
</template>

<script>
import {listSurvey2} from "@/api/system/generalsurvey";
import {treeselect} from "@/api/system/questiondomain";
import QuestionItem from '../../components/QuestionItem'
export default {
  name: "generalsurvey",
  components:{
    QuestionItem,
  },
  data(){
    return{
      domainOptions: undefined,
      domainName: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      surveyList:'',
      queryParams: {
        companyId:this.$store.state.user.compId,
        domain: 12
      },
      form :{
        questionId: null,
        companyId: null,
        naireId: null,
        userId: null,
        answer: null,
        attachments: null,
        scoreWeight: null,
        other: null,
        questionDesc: null,
        suggestion: null,
        todo: null,
        plan: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        diagnosisBy: null,
        diagnosisTime: null,
        remark: null
      }
    }
  },
  created() {
    if(this.$route.query.domainId)
      this.queryParams.domain=this.$route.query.domainId;
    this.getList();
    this.getTreeselect();
  },
  methods: {
    /** 查询普查问卷问题列表 */
    getList() {
      this.loading = true;
      listSurvey2(this.queryParams).then(response => {
        this.surveyList = response.data
        console.log( this.surveyList)
        this.loading = false;
      });
    },
    getTreeselect() {
      treeselect().then(response => {
        this.domainOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      console.log(" data.id", data.id)
      this.queryParams.domain = data.id;
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

<style scoped>

</style>
